#include "../includes/need-a-name.hh"
#include "includes/constant-advection.hh"
#include <map>

ConstantAdvection::ConstantAdvection(){
  phynumber = 2;
  physical_variable_name.push_back("density");
  physical_variable_name.push_back("rho");
  transmit_equ_parameter();
  append_parameter("u0",0.0);
  set_parameter("v0",0.0);
  set_parameter("w0",0.0);

  //std::cout<<test<<std::endl;
  //   for(auto tmpi=0; tmpi<memory::equparanum; tmpi++)
  //   para.insert(std::pair<std::string,double>("Empty",0.0));    
  
}

ConstantAdvection::~ConstantAdvection(){
}

void ConstantAdvection::get_equation_flux(int dim, double* dir, double* var, double* fequ){
  for(int tmpi=0; tmpi<memory::phynumber; tmpi++)
    fequ[tmpi]=0.0;
  if(dim==1)
    get_1d_fx(fequ,var);
  if(dim==2){
    if(std::abs(dir[0])==1.0)
      get_2d_fx(fequ,var);
    if(std::abs(dir[1])==1.0)
      get_2d_fy(fequ,var);
  }
  if(dim==3){
    if(std::abs(dir[0])==1.0)
      get_3d_fx(fequ,var);
    if(std::abs(dir[1])==1.0)
      get_3d_fy(fequ,var);
    if(std::abs(dir[2])==1.0)
      get_3d_fz(fequ,var);
  }
}

//void ConstantAdvection::get_local_vmax(int dim, double* dir, double* var, double& a_local_vmax) {
void ConstantAdvection::get_local_vmax(int index){
  int dim = gridsetting::dimension;
  if(dim==1)
    memory::local_vmax[index] = 2.0*std::abs(para["u0"])*std::sqrt(gridsetting::dimension);
  if(dim==2)
    memory::local_vmax[index] = std::sqrt(std::pow(para["u0"],2)+std::pow(para["v0"],2));
  if(dim==3)
    memory::local_vmax[index] = std::sqrt(std::pow(para["u0"],2)+std::pow(para["v0"],2)+std::pow(para["w0"],2));  
}

void ConstantAdvection::get_1d_fx(double* fequ, double* var){
  fequ[0] = para["u0"] * var[0];
}
void ConstantAdvection::get_2d_fx(double* fequ, double* var){
  fequ[0] = para["u0"] * var[0];
}
void ConstantAdvection::get_2d_fy(double* fequ, double* var){
  fequ[0] = para["v0"] * var[0];
}
void ConstantAdvection::get_3d_fx(double* fequ, double* var){
  fequ[0] = para["u0"] * var[0];
}
void ConstantAdvection::get_3d_fy(double* fequ, double* var){
  fequ[0] = para["v0"] * var[0];
}
void ConstantAdvection::get_3d_fz(double* fequ, double* var){
  fequ[0] = para["w0"] * var[0];
}
